// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// new Promise(function())
// 云函数入口函数
exports.main = async (event, context) => {
   const wxContext = cloud.getWXContext()
   var access_token = "36_AZhlzC8j2eXkqtbHYFm5D6_JItOV5ZMqbV2weg-4v9enYnzh_kIVk6fQ2jf5EttRGg1mAcs0UDUpYJzN_hln6MuwKm9yN0Wrv8aLDaIRxVqvSEp4Afc3gzyiZ955BsWtCWEadWMAiCZ7XF5CGDQaADAURE"
   wx.request({
      url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + access_token, //获取小程序B接口二维码
      method: "POST",
      responseType: 'arraybuffer', //这一行非常重要，重中之重
      data: {
         scene: '22a45fds',
         page: "pages/login/login",
         width: 280,
         is_hyaline: true
      },
      header: {
         'content-type': 'application/json;charset=utf-8'
      },
      success(res) {
         console.log(res.data);
         var base64 = wx.arrayBufferToBase64(res.data);
         // that.setData({
         //    imgurl: "data:image/PNG;base64," + base64
         // })
         // this.flag
      }
   })




   // return {
   //    event,
   //    openid: wxContext.OPENID,
   //    appid: wxContext.APPID,
   //    unionid: wxContext.UNIONID,
   // }
}